package com.ww.activiti.service.impl;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ww.orm.entity.QUserRoleEntity;
import com.ww.orm.entity.UserRoleEntity;
import com.ww.activiti.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: sunnannan
 */
@Service
public class AuthorizationServiceImpl implements AuthorizationService {

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    @Override
    public List<Long> selectRoleIdsByUserId(String userId) {
        return jpaQueryFactory.selectFrom(QUserRoleEntity.userRoleEntity)
                .where(QUserRoleEntity.userRoleEntity.userId.eq(Long.valueOf(userId)))
                .fetch().stream().map(UserRoleEntity::getRoleId).collect(Collectors.toList());
    }
}
